import request from '../utils/request'

// 查询任务列表
export const queryList = (data) => {
  return request({
    method: 'POST',
    url: 'app/rest/query/tasks',
    data: {
      ...data,
      page: 0,
      sort: "created-desc"
    }
  })
}

// 查询任务详情
export const queryDetail = (taskId) => {
  return request({
    method: 'GET',
    url: `app/rest/tasks/${taskId}`
  })
}

// 完成任务接口
export const completeTask = (data) => {
  return request({
    method: 'PUT',
    url: `app/rest/tasks/${data.id}/action/complete`
  })
}

// 完成任务接口（需要填表单的情况）
export const completeTaskForm = ({ taskId, ...data}) => {
  return request({
    method: 'POST',
    url: `app/rest/task-forms/${taskId}`,
    data: data
  })
}

// 保存任务表单
export const saveTaskForm = ({ taskId, ...data})=>{
  return request({
    method: 'POST',
    url: `app/rest/task-forms/${taskId}/save-form`,
    data: data
  })
} 

// 查询任务绑定的表单信息
export const queryTaskForm = (formId) => {
  return request({
    method: 'GET',
    url: `app/rest/task-forms/${formId}`
  })
}

// 查询任务评论
export const queryTaskComments = ({ taskId, ...params}) => {
  return request({
    method: 'GET',
    url: `app/rest/tasks/${taskId}/comments`,
    params: params
  })
}


// 添加任务评论
export const createTaskComment = ({ taskId, ...data}) => {
  return request({
    method: 'POST',
    url: `app/rest/tasks/${taskId}/comments`,
    data: data
  })
}

// 认领任务
export const claimTask = (taskId)=>{
  return request({
    method: 'PUT',
    url: `app/rest/tasks/${taskId}/action/claim`
  })
}